/*
 * HighScore.fx
 *
 * Created on 11.06.2009, 17:05:00
 */

package de.hft_stuttgart.robofight.client.javafx;
import de.hft_stuttgart.robofight.client.java.JPlayer;
import javafx.scene.Cursor;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;

import javafx.scene.control.Button;

import javafx.scene.control.ListView;

import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Rectangle;

/**
 * @author michael.rieker@web.de, ralf.dauenhauer@gmx.de
 */

public class HighScore extends CustomNode{

    package var getNodeByName : function(nodeName : String) : Node;
    package var switchNode : function(className : String) : Void;
    package var getPlayer : function() : JPlayer;


    var highScoreList = ListView {
        layoutX : getNodeByName("rahmen_highScore").layoutBounds.minX + 25,
        layoutY : getNodeByName("rahmen_highScore").layoutBounds.minY + 60,
        height: 370
        width: 650
        items:[]
        skin : Constants.getListViewSkin()
    }


    function getHighScore( i : Integer) : Void {
        var highScore = getPlayer().getHighScore(i);
        var count : Integer = 0;
        var highScoreItems = [];
        while(count < highScore.size()){
            insert (((highScore.get(count) as java.util.ArrayList).get(0)).toString()).concat(". ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(1)).toString()).concat(" | Level: ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(8)).toString()).concat(" | Exp: ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(5)).toString()).concat(" | Won: ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(2)).toString()).concat(" | Draw: ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(3)).toString()).concat(" | Lost: ").concat(
                        ((highScore.get(count) as java.util.ArrayList).get(4)).toString()).concat(" | OnlineTime: ").concat(
                        (getPlayer().formatTime((highScore.get(count) as java.util.ArrayList).get(6).toString()).concat(" | FightTime: ").concat(
                        (getPlayer().formatTime((highScore.get(count) as java.util.ArrayList).get(7).toString()))))) into highScoreList.items;
            count++;
        }
    }


    init {
        getHighScore(1);
    }

var group : Group = Group{
            content : [
                getNodeByName("background"),
                getNodeByName("logo_small"),
                getNodeByName("rahmen_highScore"),
                Button { //cancel and go back to lobby
                    layoutX : getNodeByName("button_goBack").layoutBounds.minX
                    layoutY : getNodeByName("button_goBack").layoutBounds.minY
                    text: "leave"
                    action: function():Void {
                       switchNode("Lobby");
                    }
                    font: Constants.FONT_BUTTON
                    cursor : Cursor.HAND
                    width: 150
                    height : 30
                    skin : Constants.getButtonSkin();
                },
                Rectangle {
                    var fxzLayout = getNodeByName("logout").layoutBounds;
                    x : fxzLayout.minX;
                    y : fxzLayout.minY;
                    width : 80
                    height : 15
                    cursor : Cursor.HAND;
                    onMouseClicked : function( e : MouseEvent) : Void {
                        getPlayer().logout();
                        switchNode("Login");
                    }
                    opacity:0
                },
                getNodeByName("logout"),
                highScoreList
            ]
        }

    override function create() : Node {
        return group;
    }

}
